home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / Amiga_Mail_Vol2 / Archives / Plain / so90 / Icon2of2.txt < prev    next >
Encoding:
Text File  |  1990-10-24  |  3.7 KB  |  152 lines

  1. (c)  Copyright 1990 Commodore-Amiga, Inc.   All rights reserved.
  2. The information contained herein is subject to change without notice,
  3. and is provided "as is" without warranty of any kind, either expressed
  4. or implied.  The entire risk as to the use of this information is
  5. assumed by the user.
  6.  
  7. /* wbarg.c
  8.  * How to get an icon from a Workbench argument
  9.  * Written by David N. Junod, 27-Aug-90
  10.  */
  11.  
  12. #include <exec/types.h>
  13. #include <exec/memory.h>
  14. #include <exec/libraries.h>
  15. #include <libraries/dos.h>
  16. #include <workbench/icon.h>
  17. #include <workbench/startup.h>
  18. #include <clib/dos_protos.h>
  19. #include <clib/exec_protos.h>
  20. #include <clib/wb_protos.h>
  21. #include <pragmas/dos.h>
  22. #include <pragmas/exec.h>
  23. #include <pragmas/wb.h>
  24. #include <string.h>
  25.  
  26. extern struct Library *IconBase, *DOSBase;
  27.  
  28. struct DiskObject *GetDiskObjectNew (STRPTR name);
  29. struct DiskObject *GetDiskObject (STRPTR name);
  30.  
  31. #pragma libcall IconBase GetDiskObjectNew 84 801
  32.  
  33. /****** wbarg/IconFromWBArg ********************************************
  34. *
  35. *   NAME
  36. *    IconFromWBArg - Obtains the icon from a Workbench argument.
  37. *
  38. *   SYNOPSIS
  39. *    dob = IconFromWBArg (wbarg);
  40. *
  41. *    struct DiskObject *dob;
  42. *    struct WBArg *wbarg;
  43. *
  44. *   FUNCTION
  45. *    Given a valid Workbench argument, this command will return the
  46. *    proper icon.  This call uses the new (V36) GetDiskObjectNew call
  47. *    to ensure that an icon will be returned.
  48. *
  49. *    This functions requires dos.library and icon.library to be opened
  50. *    by the application.
  51. *
  52. *   INPUTS
  53. *    wbarg    - Pointer to a filled in WBArg structure.
  54. *
  55. *   RESULTS
  56. *    dob    - Pointer to a DiskObject structure.  Application must call
  57. *          FreeDiskObject when done with the icon.
  58. *
  59. **********************************************************************/
  60.  
  61. struct DiskObject *IconFromWBArg (struct WBArg * arg)
  62. {
  63.     struct DiskObject *dob = NULL;
  64.     UBYTE work_name[34];
  65.     BPTR old, new;
  66.  
  67.     /* Copy the WBArg contents */
  68.     strcpy (work_name, arg->wa_Name);
  69.  
  70.     /* Duplicate the lock */
  71.     if (new = DupLock (arg->wa_Lock))
  72.     {
  73.     BOOL success = FALSE;
  74.  
  75.     /*
  76.      * If we don't have a name, then get one. Only Tools & Projects have a
  77.      * valid name.
  78.      */
  79.     if (strlen (work_name) == 0)
  80.     {
  81.         LONG msize = sizeof (struct FileInfoBlock);
  82.         struct FileInfoBlock *info;
  83.  
  84.         /* This block needs to be longword aligned, so allocate it */
  85.         if (info = (struct FileInfoBlock *) AllocMem (msize, MEMF_CLEAR))
  86.         {
  87.         /* Examine the lock, so that we can figure out the name */
  88.         if (Examine (new, info))
  89.         {
  90.             /* Copy the name of the lock */
  91.             strcpy (work_name, info->fib_FileName);
  92.  
  93.             /* See if the lock is a directory */
  94.             if (info->fib_DirEntryType > 0)
  95.             {
  96.             /* Unlock the existing lock */
  97.             UnLock (new);
  98.  
  99.             /* Go to the parent drawer */
  100.             if ((new = ParentDir (arg->wa_Lock)) == NULL)
  101.             {
  102.                 /* A disk icon was passed */
  103.                 strcpy (work_name, "disk");
  104.                 new = DupLock (arg->wa_Lock);
  105.  
  106.             }    /* End of if disk */
  107.             }        /* End of if directory */
  108.  
  109.             /* We have a name */
  110.             success = TRUE;
  111.  
  112.         }        /* End of examine */
  113.  
  114.         /* Free the temporary block */
  115.         FreeMem ((APTR) info, msize);
  116.         }
  117.     }
  118.     else
  119.     {
  120.         /* Show that we have a name to work with */
  121.         success = TRUE;
  122.     }
  123.  
  124.     /* See if we should try getting the icon */
  125.     if (success)
  126.     {
  127.         /* go to the directory where the icon resides */
  128.         old = CurrentDir (new);
  129.  
  130.         /*
  131.          * GetDiskObjectNew is a new function, for AmigaOS version 2.0,
  132.          * therefore we need to check the version level.
  133.          */
  134.         if (IconBase->lib_Version >= 36)
  135.         dob = GetDiskObjectNew (work_name);
  136.         else
  137.         dob = GetDiskObject (work_name);
  138.  
  139.         /* go back to where we used to be */
  140.         CurrentDir (old);
  141.     }
  142.  
  143.     /* release the duplicated lock */
  144.     UnLock (new);
  145.     }
  146.  
  147.     /* return the icon */
  148.     return (dob);
  149. }
  150.  
  151.  
  152.